home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group03a.txt
/
000092_icon-group-sender_Thu Sep 18 12:43:42 2003.msg
< prev
next >
Wrap
Internet Message Format
|
2003-12-22
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h8IJhEO27359
for icon-group-addresses; Thu, 18 Sep 2003 12:43:14 -0700 (MST)
Message-Id: <200309181943.h8IJhEO27359@baskerville.CS.Arizona.EDU>
X-Authentication-Warning: weaver.tuc.noao.edu: swampler set sender to swampler@noao.edu using -f
Subject: Re: Simple Icon programming challenge...
From: Steve Wampler <swampler@noao.edu>
To: icon-group@cs.arizona.edu
Date: Thu, 18 Sep 2003 07:52:29 -0700
X-Spam-Status: No, hits=-8.2 required=5.0
tests=BAYES_10,IN_REP_TO,REFERENCES,USER_AGENT_XIMIAN,
X_AUTH_WARNING
version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
For the record, here are two possible solutions - the first
is fairly straightforward, the second borders on the absurd...
from the far side. Both share a common ancestry and would be
cleaner if rewritten to use William's scambleinnards(words)
approach.
Solution 1:
##################################################################
# Scrambles words but leaves them 'readable' by fixing the first
# and last letters in place.
#
# Reads from standard input, writes to standard output
procedure main(args)
&random := integer(map("smhSMH","Hh:Mm:Ss",&clock))
while write(scrambleline(read()))
end
# Take a single line of input and produce it's equivalent with
# interior letters of words scrambled.
# Defines a word as any sequence of 1 or more letters,
#
procedure scrambleline(line)
local s := ""
line ? {
while s ||:= tab(upto(&letters)) || sword(tab(many(&letters)))
return s || tab(0)
}
end
# Do the actual scrambling of the word. Note that words with less
# than four letters can't be scrambled (not enough interior letters)
#
procedure sword(word)
word ?:= (move(1) || scramble(tab(1<*word)) || move(1))
return word
end
# This procedure just randomly rearranges the characters in its
# argument.
#
procedure scramble(s)
every !s :=: ?s
return s
end
#########################################################################
Solution 2 (unfit for human consumption!):
#########################################################################
#### Scrambles words but leaves them 'readable' by fixing the first
# and last letters in place.
#
# Reads from standard input, writes to standard output
procedure main(args)
&random := integer(map("smhSMH","Hh:Mm:Ss",&clock))
while read() ? {
while writes(tab(upto(&letters))) do
(w := tab(many(&letters))\1) ?
writes(move(1), {s := tab(1<*w)|"";every !s :=: ?s; s},
move(1)|"")
write(tab(0))
}
end
######################################################################
--
Steve Wampler -- swampler@noao.edu
Quantum materiae materietur marmota monax si marmota
monax materiam possit materiari?